using System.Collections;
using System.Collections.Generic;
using System.Linq.Expressions;
using Unity.VisualScripting;
using UnityEngine;

public class PlayerMove : MonoBehaviour
{
    private Transform tf;
    private Rigidbody2D rb2d;
    public float speed;
    void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
        tf = GetComponent<Transform>();
    }

    void Update()
    {
        float Horizontal = Input.GetAxis("Horizontal");
        float Vertical = Input.GetAxis("Vertical");
        float VerticalSpend = 0f;
        float HorizontalSpend = 0f;

        if ((Horizontal == 0f) == false)
        {
            HorizontalSpend = (Horizontal * speed) - rb2d.velocity.x;
            rb2d.AddForceX(HorizontalSpend , ForceMode2D.Force);
        }
        if ((Vertical == 0f) == false)
        {
            VerticalSpend = (Vertical * speed) - rb2d.velocity.y;
            rb2d.AddForceY(VerticalSpend , ForceMode2D.Force);
        }
        
        
        //rb2d.AddForce(new Vector2(Horizontal,Vertical) * speed, ForceMode2D.Force);
        //rb2d.MovePosition(new Vector2(Horizontal,Vertical) * speed);
        //rb.velocity = new Vector3(Horizontal * speed, Vertical * speed, 0f);


    }
}
